
<%@page import="java.util.Iterator"%>
<%@page import="br.com.fatecpg.babelchat.Chat"%>
<%@page import="java.util.HashMap"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Babel Chat</title>
        <link href="style.css" type="text/css" rel="stylesheet">
        <script type="text/javascript">
            function focusIn(idFocus){
        document.getElementById(idFocus).focus();
        }
        </script>
    </head>
    <body class="bodyIndex" onload="focusIn('novaSalaText')">
        <h1 class="tituloIndex">Bem vindo ao chat de babel!</h1>
        <center><div class="divIndex"><h2>Escolha uma sala ou crie uma clicando no botão ao final da lista.</h2>
        <%
            if(getServletContext().getAttribute("salas") == null){
                HashMap<String, Chat> salas = new HashMap<String, Chat>();
                getServletContext().setAttribute("salas", salas);
            }
            HashMap<String, Chat> salas = (HashMap<String, Chat>) getServletContext().getAttribute("salas");

            for(Iterator it = salas.keySet().iterator(); it.hasNext();){
                String key = (String)it.next();
        %>
        <h3><a class="salaLink" href="<%=request.getContextPath()%>/salas/<%= key%>"><%= key%></a></h3>
        <%
            }
        %>

        <input type="text" id="novaSalaText" /><input type="button" value="Criar nova sala" onclick="window.location = '/babelChat/salas/'+document.getElementById('novaSalaText').value" />
            </div></center>
        </body>
</html>
